import React from 'react';
import {connect} from 'react-redux';
import {AuthRoute, lazyImg,GoPagePush} from "../../../assets/js/utils";
import UpRefresh from "../../../assets/js/libs/uprefresh";
import Css from '../../../assets/css/user/order/index.css';
import request from "../../../assets/js/utils/request";
class orderReview extends React.Component{
    constructor(props){
        super(props);
        AuthRoute(props);
        this.state={
            aReview:[]
        }
        this.oUpRefresh=null;
        this.curPage=1;
        this.maxPage=0;
        this.offsetBottom=100
    }
    componentDidMount(){
        this.getDataReview();
    }
    //获取待评价数据
    getDataReview(){
        let sUrl=window.base.config.baseUrl+'/user/myorder/reviewOrder?uid=696443691&page='+this.curPage+'&token='+window.base.config.token;
        request(sUrl,'get').then((res)=>{
            if (res.code===200){
                this.maxPage=res.pageinfo.pagenum;
                this.setState({aReview:res.data},()=>{
                    lazyImg();
                    this.getScrollPage()
                })
            }
        })
    }
    //获取分页数据
    getScrollPage(){
        this.oUpRefresh=new UpRefresh({
                "curPage":this.curPage,
                "maxPage":this.maxPage,
                "offsetBottom":this.offsetBottom},
            curPage=>{
                let  sUrl=window.base.config.baseUrl+'/user/myorder/reviewOrder?uid='+this.props.state.redLogin.uid+'&page='+curPage+'&token='+window.base.config.token;
                request(sUrl,'get').then((res)=>{
                    if (res.code===200){
                        let temAReview=this.state.aReview;
                        for(let i in res.data){
                            temAReview.push(res.data[i])
                        }
                        this.setState({aReview:temAReview},()=>{
                            lazyImg();
                        })
                    }
                })
            });
    }
    goPages(url){
        GoPagePush(this.props,url)
    }
    componentWillUnmount(){
        this.oUpRefresh=null;
        this.setState = (state, callback) => {
            return;
        };
    }
    render(){
        return(
            <div className={Css['order_main']}>
                {
                    this.state.aReview.length>0?
                            this.state.aReview.map((item,index)=>{
                                return(
                                    <div className={Css['group']} key={index}>
                                        <div className={Css['row']}>
                                            <div className={Css['order_nub']}>订单编号：{item.ordernum}</div>
                                            <div className={Css['order_status']}>待评价</div>
                                        </div>
                                        <div className={Css['row']}>
                                            {
                                                item.goods.length>0?
                                                    item.goods.map((item2,index2)=>{
                                                        return(
                                                            <div className={Css['order_pro']} key={index2}>
                                                                <div className={Css['order_img']}>
                                                                    <img src={require('../../../assets/images/commen/lazyImg.jpg')} data-echo={item2.image} alt={item2.title} />
                                                                </div>
                                                                <div className={Css['order_font']}>
                                                                    <div className={Css['order_title']}>{item2.title}</div>
                                                                    <div className={Css['order_amount']}>x{item2.amount}</div>
                                                                    <div className={Css['order_btn']+' '+Css['mt10']} onClick={this.goPages.bind(this,'orders/addreview?gid='+item2.gid+'&ordernum='+item.ordernum)}>
                                                                        评价
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        )
                                                    })
                                                    :''
                                            }
                                        </div>
                                    </div>
                                )
                            })
                        :''
                }
            </div>
        )
    }
}
export default connect((state)=>{
    return{
        state:state
    }
})(orderReview)